package cn.aishu.anydream.service.advice;

import cn.aishu.common.AishuException;
import cn.aishu.common.ResponseModel;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理
 */
@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler
    public ResponseModel handleException(Exception e) {

        if (e instanceof AishuException) {
            // 如果异常是AishuException
            String message = ((AishuException) e).getMessage();
            ResponseModel model = new ResponseModel(false, message);

            return model;
        }

        // 未知错误
        String message = "未知错误";
        ResponseModel model = new ResponseModel(false, message);

        return model;
    }
}
